<?php
require_once '../entity/AssuntoDisciplina.php';
require_once '../entity/Assunto.php';
require_once '../entity/Disciplina.php';

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ModelAssuntoDisciplina
 *
 * @author David
 */
class ModelAssuntoDisciplina extends Model {

    // GETS
    public function getAssuntoDisciplina() {

        $this->sql = "SELECT 
                        a.codigo,
                        b.descricao as disciplina,
                        c.descricao as assunto
                      FROM 
                        assuntodisciplina a
                      INNER JOIN disciplina b ON a.disciplina = b.codigo
                      INNER JOIN assunto c ON a.assunto = c.codigo;";

        $stmt = $this->p->prepare($this->sql);
        $res = $stmt->execute();
        
        $result = [];
        if ($res != 1) {
            $result = "erro";
        } else {
            while ($linha = $stmt->fetch()) {
                $assuntoDisciplina = new AssuntoDisciplina();
                $assunto = new Assunto();
                $disciplina = new Disciplina;
                
                $assuntoDisciplina->codigo = $linha["codigo"];
                
                $assunto->descricao = $linha["assunto"];
                $assuntoDisciplina->Assunto = $assunto;
                
                $disciplina->descricao = $linha["disciplina"];
                $assuntoDisciplina->Disciplina = $disciplina;
                
                $result[] = $assuntoDisciplina;
            }
        }
        
        return $result;
    }

}

?>
